package com.muyu.system.controller;

import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.PageUtils;
import com.muyu.system.Vo.AccountLogVO;
import com.muyu.system.Vo.AccountVO;
import com.muyu.system.Vo.SecurityRefundVO;
import com.muyu.system.danmo.dto.RefundDTO;
import com.muyu.system.danmo.vo.PayVO;
import com.muyu.system.dto.AccountLogDTO;
import com.muyu.system.dto.PayDTO;
import com.muyu.system.dto.PremiumPayDTO;
import com.muyu.system.dto.SecurityRefundDTO;
import com.muyu.system.service.SecurityDepositService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 保证金
 * @author Administrator
 */
@RestController
@RequestMapping("/security/deposit")
@RequiredArgsConstructor
public class SecurityDepositController {

    private final SecurityDepositService securityDepositService;



    /**
     * 获取账户信息
     * @param storeId
     * @return
     */
    @GetMapping("/account/{storeId}")
    public Result<AccountVO> account(@PathVariable("storeId") Long storeId){
        return Result.success(securityDepositService.account(storeId));
    }


    /**
     * 获取账户流水
     * @param accountLogDTO
     * @return
     */
    @PostMapping("/account/log")
    public Result<PageInfo<AccountLogVO>> accountLog(@RequestBody  @Valid  AccountLogDTO accountLogDTO){
        return Result.success(PageUtils.convertToPageInfo(securityDepositService.accountLog(accountLogDTO)));
    }

    /**
     * 缴纳保证金
     * @param payDTO
     * @return
     */
    @PostMapping("/pay")
    public Result<PayVO> pay(@RequestBody @Valid PayDTO payDTO){
        return Result.success(securityDepositService.pay(payDTO));
    }


    /**
     * 缴纳手续费
     * @param payDTO
     * @return
     */
    @PostMapping("/premium/pay")
    public Result<PayVO> premiumPay(@RequestBody @Valid PremiumPayDTO payDTO){
        return Result.success(securityDepositService.premiumPay(payDTO));
    }

    /**
     * 退保证金
     * @param securityRefundDTO
     * @return
     */
    @PostMapping("/refund")
    public Result<SecurityRefundVO> securityRefund(@RequestBody @Valid SecurityRefundDTO securityRefundDTO){
        return Result.success(securityDepositService.securityRefund(securityRefundDTO));
    }
}
